import { createCartItem } from '@/api/shoppingCart.ts'

export const commonFormProps = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 18
  },
  autoComplete: 'off'
}

export const commonInputProps = (type: 'Input' | 'TextArea' | 'Search' | 'Password' = 'Input') => {
  switch (type) {
    case 'Input':
      return {
        allowClear: true,
        showCount: true,
        maxLength: 50,
        placeholder: '请输入'
      }
    case 'Password':
      return {
        allowClear: true,
        showCount: true,
        maxLength: 50,
        autoComplete: 'new-password',
        placeholder: '请输入'
      }
    case 'Search':
      return {
        allowClear: true,
        showCount: true,
        maxLength: 50,
        placeholder: '请输入'
      }
    case 'TextArea':
      return {
        allowClear: true,
        showCount: true,
        maxLength: 500,
        placeholder: '请输入'
      }
  }
}

export const commonSelectProps = {
  placeholder: '请选择'
}

export const addItemsToCart = async (ids: Array<string>) => {
  const reqs = ids.map((id) => createCartItem({ product_id: id }))
  await Promise.all(reqs)
}
